# -*- coding:UTF-8 -*-
"""
@Project : pythonProject
@File    : Demo01_yesterday's_homework_explanation.py
@IDE     : PyCharm
@Author  : WorldWind(1772830365@qq.com)
@Address : China - HeiLongjiang - Herbin
@Date    : 2025/7/15 上午9:38
"""
# 计算周长和面积
"""
    第一一个父类:
    Shape:定义两个方法 
        area()计算面积
        perimeter()计算周长
    父类函数体可以不实现(pass即可)
    --------------------------------------------------
    定义两个子类：
    一个是Rectangle（长方形），构造方法传入两个参数，length和width，
    Circle（圆）构造方法传入一个参数radius（半径），重写父类的两个方法

"""


class Shape:
    def __init__(self):
        print(f'This is __init__ method. {self.get_class_name()} class startup')

    # 计算面积
    def area(self):
        pass

    # 计算周长
    def perimeter(self):
        pass

    @classmethod
    def get_class_name(cls):
        return cls.__name__

    def __del__(self):
        print(f'This is __del__ method. The {self.get_class_name()} class has been recycled')


class Rectangle:
    def __init__(self, width, height):
        self.width = width
        self.height = height
        print(f'This is __init__ method. {self.get_class_name()} class startup')

    def area(self):
        return self.width * self.height

    def perimeter(self):
        return (self.width + self.height) * 2

    @classmethod
    def get_class_name(cls):
        return cls.__name__

    def __del__(self):
        print(f'This is __del__ method. The {self.get_class_name()} class has been recycled')


class Circle(Shape):

    def __init__(self, radius):
        self.radius = radius

    # 计算面积
    def area(self):
        return 3.14 * self.radius * self.radius

    # 计算周长
    def perimeter(self):
        return 2 * 3.14 * self.radius


if __name__ == '__main__':
    r = Rectangle(10, 20)
    print(r.area())
    print(r.perimeter())

    c = Circle(10)
    print(c.area())
    print(c.perimeter())
